﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Libs.Content;
using System.Web.UI.HtmlControls;

public partial class Controls_Home_HotNews : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;

        NewsWeb _NewsWeb = new NewsWeb();
        NewsCategories _Cate = new NewsCategories() { CateID = 49 };
        List<NewsWeb> list;

        list = _NewsWeb.GetList(_Cate.CateID, 0, 4);
        _Cate = _Cate.Get();

        _NewsWeb = list[0];

        rptHotNews.DataSource = list;
        rptHotNews.DataBind();
    }

    protected void rptHotNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HtmlAnchor hlimg = (HtmlAnchor)e.Item.FindControl("hlimg");
            HtmlAnchor hltitle = (HtmlAnchor)e.Item.FindControl("hltitle");
            HtmlImage img = (HtmlImage)e.Item.FindControl("img");
            HtmlGenericControl sapo = (HtmlGenericControl)e.Item.FindControl("sapo");

            NewsWeb item = (NewsWeb)e.Item.DataItem;
            if (item != null)
            {
                hlimg.HRef = item.Url;
                img.Src = AppUtils.ImageUrl(item.ImageUrl, "458", "290");
                hltitle.HRef = item.Url;
                hltitle.InnerText = item.Title;
                sapo.InnerHtml = item.SubLead;

                if (sapo.InnerHtml.Length > 180)
                {
                    sapo.InnerHtml = sapo.InnerHtml.Substring(0, 180) + "...";
                }
            }
        }
    }
}